package com.xframe.domain.role;

import com.xframe.domain.BaseModel;
import com.xframe.xdal.core.annotation.*;
import com.xframe.xdal.core.constant.AutoFillType;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 角色菜单关系
 * @ClassName: SysMenuRole
 * @Author: xufeng
 * @CreateTime: 2023/4/4 16:13
 **/
@Data
@Accessors(chain=true)
@XTable(value = "sys_menu_role", label = "角色菜单关系表")
@XBelongsTo(typeName = "com.xframe.domain.role.SysRole",foreignKey = "roleId", targetKey = "roleId", as = "sysRole")
@XBelongsTo(typeName = "com.xframe.domain.role.SysFullMenu",foreignKey = "menuId", targetKey = "menuId", as = "sysFullMenu")
public class SysMenuRole extends BaseModel {
    /**
     * 角色菜单关系ID
     */
    @AutoFill(AutoFillType.Snowflake)
    @XColumn(name = "key_id", primaryKeyFlag = true)
    private Long keyId;

    /**
     * 角色ID
     */
    @XColumn(name = "role_id", uniqueFlag = true)
    private Long roleId;

    /**
     * 视图菜单表ID
     */
    @XColumn(name = "menu_id", uniqueFlag = true)
    private Long menuId;


    public static List<String> toIdArray(List<SysMenuRole> menuRoles){

        List<String> ids = new ArrayList<>();
        if(menuRoles != null && menuRoles.size() > 0){
            for(SysMenuRole sysMenuRole : menuRoles){
                ids.add(sysMenuRole.menuId.toString());
            }
        }

        return ids;
    }

    private SysRole sysRole;

    private SysFullMenu sysFullMenu;
}
